<?php
class CatalogAction extends HomeAction {
    public function index(){
    	$catId = isset($_GET["cat"])?(int)$_GET["cat"]:1;
    	$page = isset($_GET["page"])?(int)$_GET["page"]:1;
    	
    	$this->assign("currentCat", $catId);
    	
    	$Book = D("Book");
    	$pageSize = C("PAGE_SIZE");
    	$bookList = $Book->where('catId='.$catId)->order('sortIndex')->limit(($page-1)*$pageSize.", ".$pageSize)->select();
    	$count = $Book->where('catId='.$catId)->count();
        
        import('ORG.Util.Page');
        $Page = new Page($count,$pageSize);// 实例化分页类 传入总记录数和每页显示的记录数
	//分页跳转的时候保证查询条件
	$Page->parameter = "cat=".$catId;
	$pager = $Page->show();// 分页显示输出
        $this->assign("bookList",$bookList);
        $this->assign("pager",$pager);

    	$weekRank = $Book->where('catId='.$catId)->order('weekClick')->limit(10)->select();
        $this->assign("weekRank",$weekRank);
    	$monthRank = $Book->where('catId='.$catId)->order('monthClick')->limit(10)->select();
        $this->assign("monthRank",$monthRank);
    	$totalRank = $Book->where('catId='.$catId)->order('click')->limit(10)->select();
        $this->assign("totalRank",$totalRank);
    	
    	$this->display();
    }
}
